<template>
  <div id="user-modify">
    <h2 style="text-align: center;">添加设备</h2>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="设备名称">
        <el-input v-model="form.sbName" placeholder="不可以为空"></el-input>
      </el-form-item>

        <el-form-item label="设备型号" prop="pass">
          <el-input type="text" v-model="form.sbMod" placeholder="可以为空"></el-input>
        </el-form-item>
				
				<el-form-item label="制造厂家" prop="pass">
				  <el-input type="text" v-model="form.sbFac" placeholder="可以为空"></el-input>
				</el-form-item>




      <el-form-item>
        <el-button type="primary" @click="register()">添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default{
    data(){
      return {
        form: {
          id:this.$route.params.id,
          sbName: '',
          sbMod: '',
		  sbFac: ''
        }
      }
    },
    methods:{
      register() {
        var obj = this;
        this.axios({
          method:"POST",
          url:"http://localhost:8088/sb/addSb",
          data:obj.form
        }).then(function(response){
          var result = response.data;
         if (result.code==20) {
           // 成功消息提示
           obj.$message({
             message: '该设备已经存在',
             type: 'success'
           })
         }
         if (result.code==10){
               obj.$message.error('已存在该设备，添加失败(请修改设备名再次尝试)');
             }
         if (result.code==30){
           obj.$message.error('设备名称不能为空，注册失败');
         }
		 if (result.code==100) {
		       // 成功消息提示
		       obj.$message({
		         message: '恭喜你，添加成功',
		         type: 'success'
		       }),
		       // 延时跳转
		       setTimeout(function(){
		         obj.$router.push("/sbs/sb")
		       },2000)
		     } 
        })
      }
    }
  }
</script>

<style>
  #user-modify{
    width: 400px;
    margin: auto;
  }
</style>
